package actions;


import Objects.Bomba;

import com.jme.input.action.InputAction;
import com.jme.input.action.InputActionEvent;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.PhysicsSpace;
import com.model.md5.controller.MD5Controller;

public class PlatarBomba extends InputAction {

	public class ContadorBombas {
		private int cantidadBombas;
		private int cantidadInstaladas;

		public ContadorBombas(int i) {
			cantidadBombas = i;
		}

		public void detonarBomba() {
			cantidadInstaladas--;
		};

		public int getCantidadBombas() {
			return cantidadBombas;
		}

		public int getCantidadInstaladas() {
			return cantidadInstaladas;
		}

		public boolean hayBombas() {
			return cantidadInstaladas < cantidadBombas;
		}

		public void instalarBomba() {
			cantidadInstaladas++;
		}

		public void setCantidadBombas(int cantidadBombas) {
			this.cantidadBombas = cantidadBombas;
		}

	}
	private static final float tileSize = 10;

	private ContadorBombas contador;
	private boolean[][] mazeData;
	private DynamicPhysicsNode node;
	private PhysicsSpace physicsSpace;
	private Node rootNode;
	private MD5Controller bodyController;

	
	public PlatarBomba(DynamicPhysicsNode node, Node rootNode,
			PhysicsSpace physicsSpace, boolean[][] mazeData, MD5Controller bodyController) {
		contador = new ContadorBombas(20);
		this.node = node;
		this.mazeData = mazeData;
		this.rootNode = rootNode;
		this.physicsSpace = physicsSpace;
		this.bodyController = bodyController;
	}

	@Override
	public void performAction(InputActionEvent evt) {

		if (contador.hayBombas()) {

			
			bodyController.fadeTo("plantar", 0, true);

			Bomba bomba = new Bomba(new Vector3f(node.getLocalTranslation()),
					physicsSpace, mazeData, rootNode, contador);
			
			Thread thread = new Thread(bomba);
			
			thread.start();
			
			rootNode.attachChild(bomba);
			rootNode.updateRenderState();

		}
	}

}
